home *** CD-ROM | disk | FTP | other *** search
/ Download Now 8 / Download Now V8.iso / Program / InternetTools / ApacheWebServer1.3.6 / apache_1_3_6_win32.exe / _SETUP.1 / PORTING < prev    next >
Encoding:
Text File  |  1998-09-17  |  13.6 KB  |  376 lines

  1. The Semi-Official Guide to Porting Apache
  2.  
  3. -------------
  4. Introduction:
  5. -------------
  6. Apache has been ported to a wide variety of platforms, from multiple
  7. UNIX variants to OS/2. Starting with v1.3, it will even run under
  8. Windows95 and Windows NT. Nonetheless, there are most likely a few
  9. platforms out there that currently are not "officially" supported under
  10. Apache. Porting Apache to these platforms can be quite simple
  11. depending on the "genericness" of the OS. This document will provide
  12. some basic guidelines to help the potential porter.
  13.  
  14. -------------
  15. Requirements:
  16. -------------
  17. One of the basic requirements for a potential Apache platform is
  18. a robust TCP/IP implementation. Just about any UNIX out there
  19. nowadays, even some ancient ones, have a TCP/IP stack that will
  20. work. In particular, the UNIX should provide for sockets and the
  21. basic controlling functions for them (like accept(), bind(), etc).
  22.  
  23. The source for Apache is written in ANSI-C, so an ANSI-C compiler
  24. is required. However, Apache does not use or require ANSI-only
  25. functions or options (eg: the "%n" parameter in the scanf()
  26. family) as much as possible to ease portability. Generally,
  27. an ANSI-C compiler (eg: gcc) even without a full-blown ANSI
  28. C library is usually sufficient.
  29.  
  30. At present, the Apache source is not compatible with C++.
  31.  
  32. -------------------
  33. The Starting Point:
  34. -------------------
  35. The first thing to look at is the output of the ./helpers/GuessOS
  36. script. This is a simple script that attempts to determine the
  37. platform and OS you are running on. The output of this script
  38. is used by Configure to set some basic compilation parameters.
  39.  
  40. The output of ./helpers/GuessOS was designed to be GNU 'config.guess'
  41. compatible (from GNU/autoconf). The format of the output string
  42. is:
  43.  
  44.    machine-vendor-OS
  45.  
  46. This string is returned to the main Configure script as the
  47. shell variable $PLAT. If Configure is not "aware" of that platform
  48. (or cannot correctly parse it), it will complain and die. We realize
  49. that this may not be the best solution; the intent is to get as
  50. much feedback as possible.
  51.  
  52. ----------------------
  53. Configure cannot Grok:
  54. ----------------------
  55. If this happens to you, then it means that Configure doesn't know
  56. how to configure and compile Apache for your OS. It will still try
  57. nonetheless, but at this point, all bets are off.
  58.  
  59. The best solution if this happens to you is to make Apache aware
  60. of your OS.  The first course of action is the easiest:  Look in
  61. Configure and see if there are any OSs which are similar to yours.
  62.  
  63. For example, let's say that your OS is similar to HP-UX, but that
  64. GuessOS returns "foobar-intel-hubble". You would then edit
  65. Configure as follows:
  66.  
  67.     *-hp-hpux*|*-*-hubble)
  68.     OS='HP-UX'
  69.     CFLAGS="$CFLAGS -DHPUX"
  70.     ;;
  71.  
  72. The '|*-*-hubble' was added to the switch statement for HP-UX.
  73.  
  74. Another fix may involve editing the GuessOS helper script. Let's
  75. say, for example, that your system is SysV4-based, but that
  76. GuessOS does not return that info. You could then add a switch
  77. to the script that does something like:
  78.  
  79.     *WeirdSystem*)
  80.         echo "${MACHINE}-whatever-sysv4"; exit 0
  81.         ;;
  82.  
  83. In this case, we force GuessOS to return a string that includes
  84. the "sysv4" cookie for Configure to recognize.
  85.  
  86. Unfortunately, unless you are running a very generic BSD or SysV
  87. system, no "supported" OS will be close enough in all aspects to
  88. allow for a clear (and possibly workable) build of Apache. If this
  89. is the case, you will need to port Apache to your OS.
  90.  
  91. -------------------
  92. Porting for Apache:
  93. -------------------
  94. When all else fails, it's time to hack some code. The source itself
  95. is generic enough that most ports are incredibly easy. No matter
  96. what, however, there are 2 source files that need to be updated
  97. for the port:
  98.  
  99.    ./Configure
  100.    ./include/ap_config.h
  101.  
  102. Configure:
  103. ==========
  104. Configure concerns itself with determining the OS-type for the
  105. build and setting up a few Makefile variables for the build. The
  106. most important are 'OS' and 'CFLAGS'. For example, when Configure
  107. determines a build for A/UX, it runs the following lines:
  108.  
  109.   case "$PLAT" in
  110.     *-apple-aux3*)
  111.     OS='A/UX 3.1.x'
  112.     CFLAGS="$CFLAGS -DAUX -D_POSIX_SOURCE"
  113.     LIBS="$LIBS -lposix -lbsd"
  114.     LDFLAGS="$LDFLAGS -s"
  115.     DEF_WANTHSREGEX=no
  116.     ;;
  117.  
  118. The 'OS' variable is used to define the system Apache is being built
  119. for. You will also note that 'CFLAGS' defines "-DAUX". In this case,
  120. 'AUX' is a magic cookie used by the Apache code (mainly ap_config.h [see
  121. below]) to handle OS-specific code. Each code that has and requires
  122. such OS-specific code will require a unique "system cookie" defined
  123. in 'CFLAGS'. You will also note that Configure also goes ahead and
  124. predefines the LIBS and LDFLAGS Makefile variables.
  125.  
  126. DEF_WANTHSREGEX indicates the "default" setting of the WANTHSREGEX rule.
  127. If left undefined it'll default to yes.  Yes means the src/regex/
  128. directory, containing Henry Spencer's regex library will be used rather
  129. than any system supplied regex.  It's been our experience that system
  130. supplied regex libraries are generally buggy, and should be avoided.
  131.  
  132. ap_config.h:
  133. =======
  134. The Apache code, specifically in ap_config.h, uses a variety of #defines to
  135. control how the code is compiled and what options are available for each
  136. supported OS. One of the hardest parts about the porting process is
  137. determining which of the following are applicable for your system and
  138. setup. This time using the example of AIX, we see:
  139.  
  140.    #elif defined(AIX)
  141.    #undef HAVE_GMTOFF
  142.    #undef NO_KILLPG
  143.    #undef NO_SETSID
  144.    #define HAVE_SYS_SELECT_H
  145.    #define JMP_BUF sigjmp_buf
  146.    #define HAVE_MMAP
  147.    #define USE_MMAP_SCOREBOARD
  148.    typedef int rlim_t;
  149.  
  150. The above lines describe which functions,  capabilities and specifics
  151. are required for Apache to build and run under IBM AIX (the #undefs
  152. are not strictly required, but are a Good Idea anyway).
  153.  
  154. The following several lines provide a list and short description
  155. of these #defines. By correctly #defining the ones you need in ap_config.h
  156. (wrapped by the above mentioned "system cookie"), you can fine tune the
  157. build for your OS.
  158.  
  159. --
  160.  
  161.  NEED_*:
  162.   If the particular OS doesn't supply the specified function, we use the
  163.   Apache-supplied version (in util.c). 
  164.  
  165.     NEED_STRERROR:
  166.     NEED_STRDUP:
  167.     NEED_STRCASECMP:
  168.     NEED_STRNCASECMP:
  169.     NEED_INITGROUPS:
  170.     NEED_WAITPID:
  171.     NEED_STRERROR:
  172. --
  173.  
  174.  HAVE_*:
  175.   Does this OS have/support this capability?
  176.  
  177.     HAVE_MMAP:
  178.       The OS has a working mmap() implementation
  179.  
  180.     HAVE_SHMGET:
  181.       The OS has a working shmget() (SystemV shared memory) implementation
  182.  
  183.     HAVE_GMTOFF:
  184.       Define if the OS's tm struct has the tm_gmtoff element
  185.  
  186.     HAVE_CRYPT_H:
  187.       Defined if the OS has the <crypt.h> header file. This is set
  188.       automatically during the Configure process and stored in the
  189.       src/include/ap_config_auto.h header file.
  190.  
  191.     HAVE_SYS_SELECT_H:
  192.       Defined if the OS has the <sys/select.h> header file. This is
  193.       set automatically during the Configure process and stored in the
  194.       src/include/ap_config_auto.h header file.
  195.  
  196.     HAVE_SYS_RESOURCE_H:
  197.       Defined if the OS has and supports the getrlimit/setrlimit
  198.       family. Apache uses this to determine if RLIMIT_CPU|VMEM|DATA|RLIMIT
  199.       is found and used. This also assumes that the getrlimit()/setrlimit()
  200.       functions are available as well. This is set automatically during the
  201.       Configure process and stored in the src/include/ap_config_auto.h header
  202.       file.
  203. --
  204.  
  205.  USE_*:
  206.   These #defines are used for functions and ability that aren't exactly
  207.   required but should be used.
  208.  
  209.      USE_MMAP_SCOREBOARD:
  210.       Define if the OS supports the BSD mmap() call. This is used by various
  211.       OSs to allow the scoreboard file to be held in shared mmapped-memory
  212.       instead of a real file.  Note that this is only used to determine
  213.       if mmap should be used for shared memory. If HAVE_MMAP is not
  214.       #defined, this will automatically be unset.
  215.  
  216.      USE_SHMGET_SCOREBOARD:
  217.       Define if the OS has the SysV-based shmget() family of shared-memory
  218.       functions. Used to allow the scoreboard to live in a shared-memory
  219.       slot instead of a real file. If HAVE_SHMGET is not #defined,
  220.       this will automatically be unset.
  221.  
  222.      <<NOTE: If neither USE_MMAP_SCOREBOARD or USE_SHMGET_SCOREBOARD
  223.          is defined, a file-based scoreboard will be used and
  224.          SCOREBOARD_FILE will automatically be defined >>
  225.  
  226.      USE_POSIX_SCOREBOARD:
  227.       Defined on QNX currently where the shared memory scoreboard follows
  228.       the POSIX 1003.4 spec.
  229.     
  230.      USE_OS2_SCOREBOARD:
  231.       Defined on OS2, uses OS2 primitives to construct shared memory for
  232.       the scoreboard.
  233.  
  234.      USE_LONGJMP:
  235.       Define to use the longjmp() call instead of siglongjmp()
  236.       (as well as setjmp() instead of sigsetjmp()).
  237.  
  238.      USE_MMAP_FILES:
  239.       Enable the use of mmap() for sending static files. If HAVE_MMAP
  240.       is not #defined, this will automatically be unset.
  241.  
  242.  USE_*_SERIALIZED_ACCEPT:
  243.   See htdocs/manual/misc/perf-tuning.html for an in-depth discussion of
  244.   why these are required.  These are choices for implementing a semaphore
  245.   between children entering accept().  A complete port should define one
  246.   of these, many may work and it's worthwhile timing them.  Without these
  247.   the server will not implement multiple Listen directives reliably.
  248.  
  249.      USE_FCNTL_SERIALIZED_ACCEPT:
  250.       Use fcntl() to implement the semaphore.
  251.  
  252.      USE_FLOCK_SERIALIZED_ACCEPT:
  253.       Use flock() to implement the semaphore (fcntl() is expensive on
  254.       some OSs, esp.  when using NFS).
  255.  
  256.      USE_USLOCK_SERIALIZED_ACCEPT:
  257.       Probably IRIX only: use uslock() to serialize, which is far faster
  258.       on multiprocessor boxes (and far slower on uniprocessor, yay).
  259.  
  260.      USE_SYSVSEM_SERIALIZED_ACCEPT:
  261.       Use System V semaphores to implement the semaphore.  These are
  262.       problematic in that they won't be cleaned up if apache is kill -9d,
  263.       and there's the potential of a CGI causing a denial of service
  264.       attack if it's running as the same uid as apache (i.e. suexec
  265.       is recommended on public servers).  But they can be faster than
  266.       either of fcntl() or flock() on some systems.
  267.  
  268.      USE_PTHREAD_SERIALIZED_ACCEPT:
  269.       Use POSIX mutexes to implement the semaphore.
  270.  
  271.      << NOTE: If none of the above USE_*SERIALIZED_ACCEPTs are
  272.           defined, NO_SERIALIZED_ACCEPT will automatically
  273.           be defined if MULTITHREAD is not defined >>
  274.  
  275.      SINGLE_LISTEN_UNSERIALIZED_ACCEPT:
  276.       It's safe to unserialize single-socket accept().
  277.  
  278. --
  279.  
  280.   NO_*:
  281.    These are defined if the OS does NOT have the specified function or if
  282.    we should not use it.
  283.  
  284.       NO_SHMGET:
  285.        Do not use shmget() (SystemV shared memory) at all.
  286.  
  287.       NO_MMAP:
  288.        Do not use mmap() at all.
  289.  
  290.       NO_UNISTD_H:
  291.  
  292.       NO_KILLPG:
  293.  
  294.       NO_SETSID:
  295.  
  296.       NO_USE_SIGACTION:
  297.        Do not use the sigaction() call, even if we have it.
  298.  
  299.       NO_LINGCLOSE:
  300.        Do not use Apache's soft, "lingering" close feature to
  301.        terminate connections. If you find that your server crashes
  302.        due to being choked by too many FIN_WAIT_2 network states, 
  303.        some reports indicate that #define'ing this will help.
  304.  
  305.       NO_SLACK:
  306.        Do not use the "slack" fd feature which requires a working fcntl
  307.        F_DUPFD.
  308.  
  309.       NO_GETTIMEOFDAY:
  310.        OS does not have the gettimeofday() function (which is
  311.        BSDish).
  312.  
  313.       NO_TIMES:
  314.        OS does not have the times() function.
  315.  
  316.       NO_OTHER_CHILD:
  317.        Do not implement the register_other_child API, usually because
  318.        certain system calls aren't available.
  319.  
  320.       NO_RELIABLE_PIPED_LOGS:
  321.        Do not use reliable piped logs, which happen to also require
  322.        the register_other_child API.  The reliable piped log code
  323.        requires another child spawning interface which hasn't been
  324.        generalised yet.
  325.  
  326. --
  327.  
  328.   MISC #DEFINES:
  329.    Various other #defines used in the code.
  330.  
  331.       MULTITHREAD:
  332.        Defined if the OS is multi-threaded. Valid only on
  333.        Win32 at present.
  334.  
  335.       JMP_BUF:
  336.        The variable-type for siglongjmp() or longjmp() call.
  337.  
  338.       MOVEBREAK:
  339.        Amount to move sbrk() breakpoint, if required, before attaching
  340.        shared-memory segment.
  341.  
  342.       NET_SIZE_T:
  343.        Some functions such as accept(), getsockname(), getpeername() take
  344.        an int *len on some architectures and a size_t *len on others.
  345.        If left undefined apache will default it to int.  See
  346.        include/ap_config.h for a description of NET_SIZE_T.
  347.  
  348.       NEED_HASHBANG_EMUL:
  349.        The execve()/etc. functions on this platform do not deal with #!,
  350.        so it must be emulated by Apache.
  351.  
  352.       SYS_SIGLIST
  353.        Should be defined to point to a const char * const * array of
  354.        signal descriptions.  This is frequently sys_siglist or
  355.        _sys_siglist, defined in <signals.h>
  356.  
  357.       ap_wait_t
  358.        The type used for wait()/waitpid()/... status parameter.  Usually
  359.        int.
  360.  
  361. -----------
  362. Conclusion:
  363. -----------
  364. The above hints, and a good understanding of your OS and Apache, will
  365. go a LONG way in helping you get Apache built and running on your
  366. OS. If you have a port, PLEASE send Email to 'Apache@Apache.Org',
  367. or log a suggestion report at <http://bugs.apache.org/>, with
  368. the patches so that we may add them to the official version.
  369. If you hit a rough spot in the porting process, you can also try
  370. sending Email to that address as well and, if you are lucky, someone
  371. will respond. Another good source is the 'comp.infosystems.www.servers.unix'
  372. Usenet group as well.
  373.  
  374. Good luck and happy porting!
  375.  
  376.